﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class MasterPage_Default : System.Web.UI.MasterPage
{
    Common comm = new Common();
	public DataTable dtt_menu,dtt_right;
    protected void Page_Load(object sender, EventArgs e)
    {
	
        ContentPlaceHolder_Defualt_top_banner.Controls.Add(new UserControl().LoadControl("~/web/Controls/Ctrl_vl_top_banner.ascx"));
        Session.Remove("home");
        Session.Add("home", "1");
		dtt_menu = comm.getDataTable("select * from CreatePages_page where active=1");
        if (Request.Params["page"] != null)
        {
            switch (Request.Params["page"])
            {
                case "tintuc":
                    ContentPlaceHolder_Default_Content_Left.Controls.Add(new UserControl().LoadControl("~/web/Controls/ctrl_vl_left_news_details.ascx"));
                    break;
                case "dstintuc":
                    ContentPlaceHolder_Default_Content_Left.Controls.Add(new UserControl().LoadControl("~/web/Controls/ctrl_vl_left_news_list.ascx"));
                    break;
                case "dsvanban":
                    ContentPlaceHolder_Default_Content_Left.Controls.Add(new UserControl().LoadControl("~/web/Controls/ctrl_vl_left_vanban_list.ascx"));
                    break;
                case "dschinhsach":
                    ContentPlaceHolder_Default_Content_Left.Controls.Add(new UserControl().LoadControl("~/web/Controls/ctrl_vl_left_chinhsach_list.ascx"));
                    break;
                case "dsxkld":
                    ContentPlaceHolder_Default_Content_Left.Controls.Add(new UserControl().LoadControl("~/web/Controls/ctrl_vl_left_xkld_list.ascx"));
                    break;
                case "xkld_chitiet":
                    ContentPlaceHolder_Default_Content_Left.Controls.Add(new UserControl().LoadControl("~/web/Controls/ctrl_vl_left_xkld_details.ascx"));
                    break;
                case "ntv_chitiet":
                    ContentPlaceHolder_Default_Content_Left.Controls.Add(new UserControl().LoadControl("~/web/Controls/ctrl_vl_left_ntv_details.ascx"));
                    break;
                case "vtn_chitiet":
                    ContentPlaceHolder_Default_Content_Left.Controls.Add(new UserControl().LoadControl("~/web/Controls/ctrl_vl_left_vtn_details.ascx"));
                    break;
                case "kdt_chitiet":
                    ContentPlaceHolder_Default_Content_Left.Controls.Add(new UserControl().LoadControl("~/web/Controls/ctrl_vl_left_kdt_details.ascx"));
                    break;
                case "kdt_ds_dk":
                    ContentPlaceHolder_Default_Content_Left.Controls.Add(new UserControl().LoadControl("~/web/Controls/ctrl_vl_left_kdt_ds_ketqua.ascx"));
                    break;
                case "gioithieu":
                    ContentPlaceHolder_Default_Content_Left.Controls.Add(new UserControl().LoadControl("~/web/Controls/ctrl_vl_left_gioithieu.ascx"));
                    break;
                case "kdt_list":
                    ContentPlaceHolder_Default_Content_Left.Controls.Add(new UserControl().LoadControl("~/web/Controls/vl_left_Kdt_list.ascx"));
                    break;
				case "san_ds":
                    ContentPlaceHolder_Default_Content_Left.Controls.Add(new UserControl().LoadControl("~/web/Controls/ctrl_san_ds.ascx"));
                    break;
				case "lien_he":
                    ContentPlaceHolder_Default_Content_Left.Controls.Add(new UserControl().LoadControl("~/web/Controls/home_lien_he.ascx"));
                    break;
            }
        }
        else
        { 
            ContentPlaceHolder_Default_Content_Left.Controls.Add(new UserControl().LoadControl("~/web/Controls/ctrl_vl_left_home.ascx"));
        }

		//Cau hinh trang chu block Right:
        //7:bảng cung cầu
        //8:bộ đếm lượt truy cập
        //9:hỗ trợ trực tuyến
        //10:liên kết website

        string sql_select = "SELECT B.*,C.* FROM dbo.CreatePages_page_block AS B" +
                                " INNER JOIN dbo.CreatePages_block AS C ON B.id_block = C.id_block"+
						" INNER JOIN dbo.CreatePages_page as D ON D.id_page=B.id_page";
        string sql_where = " WHERE D.notes is NOT NULL and C.position='right'"; //id của trường trang chủ là 6, thay đổi theo csdl
        dtt_right = comm.getDataTable(sql_select + sql_where);
        if (dtt_right.Rows.Count > 0)
        {
            //Quét có block nào thì cho hiển thị block đó, nếu không cho ẩn đi
            ctrl_vl_right_bancungcau.Visible = false; ctrl_vl_right_counter.Visible = false;
            ctrl_vl_right_support.Visible = false; ctrl_vl_right_link.Visible = false;
            for (int i = 0; i < dtt_right.Rows.Count; i++)
            {
                switch (dtt_right.Rows[i]["id_block"].ToString())
                {
                    case "7": ctrl_vl_right_bancungcau.Visible = true; break;
                    case "8": ctrl_vl_right_counter.Visible = true; break;
                    case "9": ctrl_vl_right_support.Visible = true; break;
                    case "10": ctrl_vl_right_link.Visible = true; break;
                }
            }
        }
        else { 
           //Ko làm gì cả, cho hiển thị đầy đủ các block
            ctrl_vl_right_bancungcau.Visible = true; ctrl_vl_right_counter.Visible = true;
            ctrl_vl_right_support.Visible = true; ctrl_vl_right_link.Visible = true;
        }
    }
}
